﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Xml;
using System.IO;
using System.Windows.Media.Imaging;
using ThreeByte.ActiveDeck.Service;
using System.Xml.Linq;
using ThreeByte.ActiveDeck.Data;
using System.Diagnostics;

namespace ThreeByte.ActiveDeck.WebServiceTest
{
    class Program
    {
        static void Main(string[] args) {

            Stopwatch sw = Stopwatch.StartNew();
            UploadResource();
            //CreateNewPresentation();
            Console.WriteLine("Elapsed Time: {0}", sw.Elapsed);
            Console.ReadLine();
            return;

            Uri imageUri = new Uri(@"C:\Users\chris\Desktop\Infiniti Old\New Mode 8 Slides\Slide18.JPG");

            BitmapImage theImage = new BitmapImage();
            theImage.BeginInit();
            theImage.CacheOption = BitmapCacheOption.OnLoad;
            theImage.UriSource = imageUri;
            theImage.EndInit();
            //theImage.Freeze();
            
            //WebGraphicResource newGraphic = new WebGraphicResource("Pres1", "Screen1.png", theImage);


            //try {
            //    newGraphic.Upload();


            //    //var uri = "http://localhost/PowerPad.Web/PowerPadConfigService.svc/Resource/Presentation1/file.txt";

            //    //var req = WebRequest.Create(uri) as HttpWebRequest;
            //    //if (req != null) {
            //    //    req.Method = "POST";
            //    //    //req.ContentType = "image/jpeg"; 
            //    //    req.ContentType = "text/plain";
            //    //    var reqStream = req.GetRequestStream();

            //    //    //var imageStream = new MemoryStream();  
            //    //    //using (var i = Image.FromFile(@"c:\photo.jpg"))   
            //    //    //    i.Save(imageStream, ImageFormat.Jpeg);  

            //    //    //                     FileStream fs = new FileStream(@"C:\Users\chris\Desktop\LS Agenda FINAL.xls", FileMode.Open);

            //    //    //var imageArray = imageStream.ToArray();  
            //    //    var imageArray = File.ReadAllBytes(@"C:\Users\chris\Desktop\LS Agenda FINAL.xls");

            //    //    reqStream.Write(imageArray, 0, imageArray.Length);
            //    //    reqStream.Close();
            //    //    var resp = (HttpWebResponse)req.GetResponse();
            //    //    var r = new XmlTextReader(resp.GetResponseStream());
            //    //    if (r.Read()) {
            //    //        Console.WriteLine(r.ReadString());
            //    //    }
            //    //}
            //    Console.WriteLine("Press <ENTER> to quit.");
            //    Console.ReadLine();
            //} catch (Exception ex) {
            //    Console.WriteLine(ex.Message);
            //    Console.ReadKey();
            //}

        }

        public static void UploadResource() {
            WebServiceClient client = new WebServiceClient();

            GraphicResource res = new GraphicResource("TestImage", new Uri(@"C:\Users\chris\Desktop\Untitled.png"));
            //using(FileStream fs = new FileStream(@"C:\Users\chris\Desktop\Capture.PNG", FileMode.Open)){
            bool returnValue = client.UploadResource("123456", Guid.NewGuid().ToString(), res, new NetworkCredential("chris@3-byte.com", "Keitel123!"));
            Console.WriteLine("returned: {0}", returnValue);
            //}
        }


        public static void CreateNewPresentation() {

            NetworkCredential cred = new NetworkCredential("chris@3-byte.com", "Keitel123!");
            WebServiceClient client = new WebServiceClient();

            XElement response = client.NewPresentation("New Presentation", cred);

            Console.ReadLine();
        }
    }
}
